package cn.xiehangs;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class 切屏动画 extends Actor {
    Texture[] textures;
    int now = 0;//当前帧
    int max ;//最大帧
    int time = 0;//计时器
    int maxTime = 2;//几帧一换
    boolean is_able = false;//是否点击
    boolean isEnd = true;//是否结束
    public 切屏动画(Texture[] textures){
        this.textures = textures;
        this.max = textures.length;
    }
    public 切屏动画(Texture[] textures,int maxTime){
        this.textures = textures;
        this.max = textures.length;
        this.maxTime = maxTime;
    }
    public 切屏动画(String[] paths){
        this.max = paths.length;
        this.textures = new Texture[max];
        for(int i=0;i<max;i++){
            textures[i] = new Texture(paths[i]);
        }
    }

    public void act(float delta){//逻辑
        super.act(delta);
        if (!is_able){
            is_able = true;
            isEnd = false;
        }
        if(!isEnd){
            time++;
            if(time>maxTime){
                time = 0;
                now++;
                if(now>=max){
                    isEnd = true;
                    now = 0;
                }
            }
        }
    }
    public void draw(Batch batch, float parentAlpha){//绘制
        if(!isEnd){
            batch.draw(textures[now],0,0, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        }
    }
}
